﻿#pragma once

#include "resource.h"

// 1. 添加引用  LibBase
// 2. 添加 LibBase  的 include path
// 3. C++ 设置为 C++17
// 4. 使用多字节字符集
// 5. 不使用预编译头
// 6. hlsl文件 不参与生成
// 7. /utf-8



#include "BaseApp.h"
#include "Camera.h"
#include "VertexShader.h"
#include "PixelShader.h"
#include "MeshData.h"
#include "GameObject.h"
using namespace Base;



// 测试 VertexID/PrimitiveID/InstanceID

struct BufPerFrameData {
	Matrix4x4 projMat;
	Matrix4x4 viewMat;
};

struct BufPerObjectData {
	Matrix4x4 worldMat;
};

class Demo2 :public BaseApp {
public:
	virtual void OnResize() override;
	virtual void OnInit() override;
	virtual void OnGUI() override;
	virtual void OnInput() override;
	virtual void OnUpdate() override;
	virtual void OnFrame() override;
	virtual void OnTerminate() override;

private:

	template<typename T>
	void CreateConstantBuffer(ID3D11Buffer **ppBuffer) {
		D3D11_BUFFER_DESC cbd = {};
		cbd.Usage = D3D11_USAGE_DYNAMIC;
		cbd.ByteWidth = sizeof(T);
		cbd.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
		cbd.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
		D_HRESULT(m_graphics->GetDevice()->CreateBuffer(&cbd, nullptr, ppBuffer));
	}

private:
	ThirdPersonCamera mCamera;

	// shader
	std::shared_ptr<VertexShader> mVertexShader;
	std::shared_ptr<PixelShader> mPixelShader;
	std::shared_ptr<VertexShader> mInstanceVertexShader;
	std::shared_ptr<PixelShader> mInstancePixelShader;

	// mesh
	MeshData mMeshData0;

	//objs
	std::vector<std::shared_ptr<GameObject>> mObjs;
	std::shared_ptr<GameObject> mObjInstance;
	std::vector<std::shared_ptr<Transform>> mTransformVec;

	// 有几个constantbuffer??
	ComPtr<ID3D11Buffer> mDxBufPerFrame;
	ComPtr<ID3D11Buffer> mDxBufPerObject;
	BufPerFrameData mBufPerFrameData;
	BufPerObjectData mBufPerObjectData;
};

